import copy

class Parameter:

    """element name to atomic number dictionary."""
    _elem2an = {'H': 1, 'He': 2, 'Li': 3, 'Be': 4, 'B': 5, 'C': 6, 'N': 7,
                'O': 8, 'F': 9, 'Ne': 10, 'Na': 11, 'Mg': 12, 'Al': 13,
                'Si': 14, 'P': 15, 'S': 16, 'Cl': 17, 'Ar': 18, 'K': 19,
                'Ca': 20, 'Sc': 21, 'Ti': 22, 'V': 23, 'Cr': 24, 'Mn': 25, 'Fe': 26,
                'Co': 27, 'Ni': 28, 'Cu': 29, 'Zn': 30, 'Ga': 31, 'Ge': 32,
                'As': 33, 'Se': 34, 'Br': 35, 'Kr': 36, 'Rb': 37, 'Sr': 38,
                'Y': 39, 'Zr': 40, 'Nb': 41, 'Mo': 42, 'Tc': 43, 'Ru': 44,
                'Rh': 45, 'Pd': 46, 'Ag': 47, 'Cd': 48, 'In': 49, 'Sn': 50,
                'Sb': 51, 'Te': 52, 'I': 53, 'Xe': 54, 'Cs': 55, 'Ba': 56,
                'La': 57, 'Ce': 58, 'Pr': 59, 'Nd': 60, 'Pm': 61, 'Sm': 62,
                'Eu': 63, 'Gd': 64, 'Tb': 65, 'Dy': 66, 'Ho': 67, 'Er': 68,
                'Tm': 69, 'Yb': 70, 'Lu': 71, 'Hf': 72, 'Ta': 73, 'W': 74,
                'Re': 75, 'Os': 76, 'Ir': 77, 'Pt': 78, 'Au': 79, 'Hg': 80,
                'Tl': 81, 'Pb': 82, 'Bi': 83, 'Po': 84, 'At': 85, 'Bq': 0,
                }
    _LJr = {'H' : 2.886, 'He': 2.362, 'Li': 2.451, 'Be': 2.745, 'B' : 4.083,
            'C' : 3.851, 'N' : 3.660, 'O' : 3.500, 'F' : 3.364, 'Ne': 3.243,
            'Na': 2.983, 'Mg': 3.021, 'Al': 4.499, 'Si': 4.295, 'P' : 4.147,
            'S' : 4.035, 'Cl': 3.947, 'Ar': 3.868, 'K' : 3.812, 'Ca': 3.399,
            'Sc': 3.295, 'Ti': 3.175, 'V' : 3.144, 'Cr': 3.023, 'Mn': 2.961,
            'Fe': 2.912, 'Co': 2.872, 'Ni': 2.834, 'Cu': 3.495, 'Zn': 2.763,
            'Ga': 4.383, 'Ge': 4.280, 'As': 4.230, 'Se': 4.205, 'Br': 4.189,
            'Kr': 4.141, 'Rb': 4.114, 'Sr': 3.641, 'Y' : 3.345, 'Zr': 3.124,
            'Nb': 3.165, 'Mo': 3.052, 'Tc': 2.998, 'Ru': 2.963, 'Rh': 2.929,
            'Pd': 2.899, 'Ag': 3.148, 'Cd': 2.848, 'In': 4.463, 'Sn': 4.392,
            'Sb': 4.420, 'Te': 4.470, 'I' : 4.500, 'Xe': 4.404, 'Cs': 4.517,
            'Ba': 3.703, 'La': 3.522, 'Ce': 3.556, 'Pr': 3.606, 'Nd': 3.575,
            'Pm': 3.547, 'Sm': 3.520, 'Eu': 3.493, 'Gd': 3.368, 'Tb': 3.451,
            'Dy': 3.428, 'Ho': 3.409, 'Er': 3.391, 'Tm': 3.374, 'Yb': 3.355,
            'Lu': 3.640, 'Hf': 3.141, 'Ta': 3.170, 'W' : 3.069, 'Re': 2.954,
            'Os': 3.120, 'Ir': 2.840, 'Pt': 2.754, 'Au': 3.293, 'Hg': 2.705,
            'Tl': 4.347, 'Pb': 4.297, 'Bi': 4.370, 'Po': 4.709, 'At': 4.750,
            'Bq': 0,
            }
    _vdwr = {'H' :1.10,'He':1.40,'Li':1.82,'Be':1.53,'B' :1.92,
             'C' :1.70,'N' :1.55,'O' :1.52,'F' :1.47,'Ne':1.54,
             'Na':2.27,'Mg':1.73,'Al':1.84,'Si':2.10,'P' :1.80,
             'S' :1.80,'Cl':1.75,'Ar':1.88,'K' :2.75,'Ca':2.31,
             'Sc':2.11,'Ti':0.00,'V' :0.00,'Cr':0.00,'Mn':0.00,
             'Fe':0.00,'Co':0.00,'Ni':1.63,'Cu':1.40,'Zn':1.39,
             'Ga':1.87,'Ge':2.11,'As':1.85,'Se':1.90,'Br':1.85,
             'Kr':2.02,'Rb':3.03,'Sr':2.49,'Y' :0.00,'Zr':0.00,
             'Nb':0.00,'Mo':0.00,'Tc':0.00,'Ru':0.00,'Rh':0.00,
             'Pd':1.63,'Ag':1.72,'Cd':1.58,'In':1.93,'Sn':2.17,
             'Sb':2.06,'Te':2.06,'I' :1.98,'Xe':2.16,'Cs':3.43,
             'Ba':2.68,'La':0.00,'Ce':0.00,'Pr':0.00,'Nd':0.00,
             'Pm':0.00,'Sm':0.00,'Eu':0.00,'Gd':0.00,'Tb':0.00,
             'Dy':0.00,'Ho':0.00,'Er':0.00,'Tm':0.00,'Yb':0.00,
             'Lu':0.00,'Hf':0.00,'Ta':0.00,'W' :0.00,'Re':0.00,
             'Os':0.00,'Ir':0.00,'Pt':1.75,'Au':1.66,'Hg':1.55,
             'Tl':1.96,'Pb':2.02,'Bi':2.07,'Po':1.97,'At':2.02,
             'Rn':2.20,'Fr':3.48,'Ra':2.83,'Ac':0.00,'Th':0.00,
             'Pa':0.00,'U':1.86}
    """Covalent radii in A from analysis of the Cambridge Structural Database, 
    which contains about 1,030,000 crystal structures, DOI: 10.1039/b801115j
    the second element is standard deviation
    """
    _covr = {'H' :[0.31,0.05],'He':[0.28,0.00],'Li':[1.28,0.07],'Be':[0.96,0.03],
        'B' :[0.84,0.03],'C' :[0.76,0.01],'N' :[0.71,0.01],'O' :[0.66,0.02],
        'F' :[0.57,0.03],'Ne':[0.58,0.00],'Na':[1.66,0.09],'Mg':[1.41,0.07],
        'Al':[1.21,0.04],'Si':[1.11,0.02],'P' :[1.07,0.03],'S' :[1.05,0.03],
        'Cl':[1.02,0.04],'Ar':[1.06,0.01],'K' :[2.03,0.01],'Ca':[1.76,0.01],
        'Sc':[1.70,0.07],'Ti':[1.60,0.08],'V' :[1.53,0.08],'Cr':[1.39,0.05],
        'Mn':[1.61,0.08],'Fe':[1.52,0.06],'Co':[1.50,0.07],'Ni':[1.24,0.04],
        'Cu':[1.32,0.04],'Zn':[1.22,0.04],'Ga':[1.22,0.03],'Ge':[1.20,0.04],
        'As':[1.19,0.04],'Se':[1.20,0.04],'Br':[1.20,0.03],'Kr':[1.16,0.04],
        'Rb':[2.20,0.09],'Sr':[1.95,0.01],'Y' :[1.90,0.07],'Zr':[1.75,0.07],
        'Nb':[1.64,0.06],'Mo':[1.54,0.05],'Tc':[1.47,0.07],'Ru':[1.46,0.07],
        'Rh':[1.42,0.07],'Pd':[1.39,0.06],'Ag':[1.45,0.05],'Cd':[1.44,0.09],
        'In':[1.42,0.05],'Sn':[1.39,0.04],'Sb':[1.39,0.05],'Te':[1.38,0.04],
        'I' :[1.39,0.03],'Xe':[1.40,0.09],'Cs':[2.44,0.01],'Ba':[2.15,0.01],
        'La':[2.07,0.08],'Ce':[2.04,0.09],'Pr':[2.03,0.07],'Nd':[2.01,0.06],
        'Pm':[1.99,0.00],'Sm':[1.98,0.08],'Eu':[1.98,0.06],'Gd':[1.96,0.06],
        'Tb':[1.94,0.05],'Dy':[1.92,0.07],'Ho':[1.92,0.07],'Er':[1.89,0.06],
        'Tm':[1.90,0.01],'Yb':[1.87,0.08],'Lu':[1.87,0.08],'Hf':[1.45,0.01],
        'Ta':[1.70,0.08],'W' :[1.62,0.07],'Re':[1.51,0.07],'Os':[1.44,0.04],
        'Ir':[1.41,0.06],'Pt':[1.36,0.05],'Au':[1.36,0.06],'Hg':[1.32,0.05],
        'Tl':[1.45,0.07],'Pb':[1.46,0.05],'Bi':[1.48,0.04],'Po':[1.40,0.04],
        'At':[1.50,0.00],'Rn':[1.50,0.00],'Fr':[2.60,0.00],'Ra':[2.21,0.02],
        'Ac':[2.15,0.01],'Th':[2.06,0.06],'Pa':[2.00,0.01],'U' :[1.96,0.07],
        'Np':[1.90,0.01],'Pu':[1.87,0.01],'Am':[1.80,0.06],'Cm':[1.69,0.03]}

    _an2elem = dict((value, key) for key, value in _elem2an.items())
    """atomic number to element name dictionary.
    iparm is three fraction number fa,fb,fc, so that image atoms are in the range
    of a*(-fa,1+fa), b*(-fb,1+fb), c*(-fc,1+fc)"""
    _elem2mass= {'H':1.00797, 'He':4.00260, 'Li':6.941, 'Be':9.01218, 'B':10.81,
                 'C':12.011, 'N':14.0067, 'O':15.9994, 'F':18.998403, 'Ne':20.179,
                 'Na':22.98977, 'Mg':24.305, 'Al':26.98154, 'Si':28.0855, 'P':30.97376,
                 'S':32.06, 'Cl':35.453, 'Ar':39.948, 'K':39.0983, 'Ca':40.08,
                 'Sc':44.9559, 'Ti':47.90, 'V':50.9415, 'Cr':51.996, 'Mn':54.9380,
                 'Fe':55.847, 'Ni':58.70, 'Co':58.9332, 'Cu':63.546, 'Zn':65.38,
                 'Ga':69.72, 'Ge':72.59, 'As':74.9216, 'Se':78.96, 'Br':79.904,
                 'Kr':83.80, 'Rb':85.4678, 'Sr':87.62, 'Y':88.9059, 'Zr':91.22,
                 'Nb':92.9064, 'Mo':95.94, 'Tc':98, 'Ru':101.07, 'Rh':102.9055,
                 'Pd':106.4, 'Ag':107.868, 'Cd':112.41, 'In':114.82, 'Sn':118.710,
                 'Sb':121.75, 'I':126.9045, 'Te':127.60, 'Xe':131.30, 'Cs':132.9054,
                 'Ba':137.33, 'La':138.9055, 'Ce':140.12, 'Pr':140.9077, 'Nd':144.24,
                 'Pm':145, 'Sm':150.4, 'Eu':151.96, 'Gd':157.25, 'Tb':158.9254,
                 'Dy':162.50, 'Ho':164.9304, 'Er':167.26, 'Tm':168.9342, 'Yb':173.04,
                 'Lu':174.967, 'Hf':178.49, 'Ta':180.9479, 'W':183.85, 'Re':186.207,
                 'Os':190.2, 'Ir':192.22, 'Pt':195.09, 'Au':196.9665, 'Hg':200.59,
                 'Tl':204.37, 'Pb':207.2, 'Bi':208.9804, 'Po':209, 'At':210,'Bq':0
                 }


    def __init__(self):
        self.covr = copy.deepcopy(self._covr)
        self.vdwr = copy.deepcopy(self._vdwr)
        self.elem2an = self._elem2an
        self.an2elem = {v:k for k,v in self.elem2an.items()}
        self.elem2mass = self._elem2mass
